import React from "react";
import TextChatDialog from '../../../components/textChatDialog/TextChatDialog';
import { useAnswerState } from "../models/answerState";
import config from "../../../config/config";

const AnswerPage = (props) => {

    const {
        loading, setLoading,
        textChatMessages, setTextChatMessages,
        selectedPattern, setSelectedPattern,
        focusBlurFlag, setFocusBlurFlag,
        completeStatus, setCompleteStatus,
        workflowGraph, setWorkflowGraph,
        onSendChat
    } = useAnswerState();

    const patternOptions = config.agent_patterns.map(item => {
        let optionObj = new Object();
        optionObj.label = item.key + "（" + item.name + "）";
        optionObj.value = item.key;
        optionObj.disabled = item.disabled;
        return optionObj;
    });

    const textChatDialogProps = {
        loading,
        libraryVisible: false,
        pageSource: "answer",
        textChatMessages,
        setTextChatMessages,
        selectedPattern,
        focusBlurFlag,
        completeStatus,
        patternOptions,
        workflowGraph,
        selectDocument: null,
        focusBlurTextArea: setFocusBlurFlag,
        selectPattern: (pattern) => {
            setSelectedPattern(pattern);

            const image_name = "Agent_" + pattern + "_Workflow.png";
            const image_path = "D:/Downloads/taixu/images/agentics/" + image_name;
            fetch('http://localhost:5000/common/download_image?image_path=' + image_path).then(res => res.blob()).then(res => {
                setWorkflowGraph(URL.createObjectURL(res));
            });
        },
        onSendChat: (values, query) => onSendChat(values, query)
    }

    return (
        <div style={{ width: "100%", height: "100%" }}>
            <TextChatDialog { ...textChatDialogProps } />
        </div>
    );
}

export default AnswerPage;
